package com.tjetc.service;

import com.tjetc.dao.TeamDao;
import com.tjetc.domain.BossTeam;
import com.tjetc.domain.Player;
import com.tjetc.domain.Team;
import com.tjetc.utils.Db;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;

public class TeamService {
    private  TeamDao teamDao=new TeamDao();


    public  boolean add(Team team,int id) {
        try {
            QueryRunner queryRunner=new QueryRunner();
            //开启事务
            Db.start();
            //添加球队
            teamDao.add(team,id);
            Db.commit();
            return true;
        } catch (SQLException e) {
            e.printStackTrace();
            Db.rollback();
        } finally {
            Db.close();
        }
        return false;
    }

    public Team findByTeamName(String TeamName ) {
        try {
            return teamDao.findByTeamName(TeamName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public boolean del(Team team) {
        try {
            teamDao.del(team);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }


    public List<Team> showAll() {
        try {
            return teamDao.showAll();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public boolean update(int teamId, String teamName1, Date date,String teamName) {
        try {
            QueryRunner queryRunner =new QueryRunner();
            //开启事务
            Db.start();
            teamDao.update(teamId,teamName1,date,teamName);
            Db.commit();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            Db.rollback();
        } finally {
            Db.close();
        }
        return false;
    }


    public BossTeam findByTeamId(int id) {
        try {
            return teamDao.findByTeamId(id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
